<?php
/**
 * Created by PhpStorm.
 * User: hui
 * Date: 2017/2/18
 * Time: 16:59
 */
namespace app\api\controller;

class Huomao extends Base
{
    protected $type = [
        'csgo'  => 'CSGO',
        'dota2' => 'dota2',
    ];

    public function select($type)
    {
        $type = $this->type[strtolower($type)];
        $website = $this->getWeb('huomao');
        $url = $website['url'] . $type;
        $data = $this->getData($url);
        if ($data['status']) {
            $liveInfo = [];
            foreach ($data['data']['channelList'] as $roomInfo) {
                if ($roomInfo['is_live'] == 1) {
                    if (strpos($roomInfo['views'], '万') === false) {
                        $roomInfo['views'] = str_replace(',', '', $roomInfo['views']);
                        $roomInfo['views_real'] = $roomInfo['views'];
                    } else {
                        $roomInfo['views_real'] = $roomInfo['views'] * 10000;
                    }
                    $liveInfo[] = [
                        'room_id'         => $roomInfo['id'],
                        'room_name'       => $roomInfo['channel'],
                        'room_views'      => $roomInfo['views'],
                        'room_views_real' => $roomInfo['views_real'],
                        'room_username'   => $roomInfo['username'],
                        'room_image_url'  => $roomInfo['image'],
                        'room_url'        => 'http://www.huomao.com/' . $roomInfo['room_number'],
                        'room_offer'      => 'huomao'
                    ];
                }
            }
            if (empty($liveInfo)) {
                $liveInfo = true;
            }
            return $liveInfo;
        } else {
            return [];
        }
    }
}